package com.rongshu.sendmessage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.rongshu.sendmessage.R;
import com.rongshu.sendmessage.bean.QuanXianBean;

import java.util.List;


public class QuanxianAdapter extends BaseAdapter {
    private final Context context;
    private List<QuanXianBean> list;
    private final LayoutInflater inflater;

    public QuanxianAdapter(Context context, List<QuanXianBean> list) {
        this.context=context;
        this.list=list;
        this.inflater= LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView==null){
            holder=new Holder();
            convertView=inflater.inflate(R.layout.quanxian_item,null);
            holder.tv_state=convertView.findViewById(R.id.tv_state);
            holder.tv_title=convertView.findViewById(R.id.tv_title);
            holder.tv_des=convertView.findViewById(R.id.tv_des);
            convertView.setTag(holder);
        }else{
            holder= (Holder) convertView.getTag();
        }

        QuanXianBean quanXianBean = list.get(position);
        if (quanXianBean.isOpen()){
            holder.tv_state.setTextColor(context.getResources().getColor(R.color.copy_color));
            holder.tv_state.setText("已开启");
        }else{
            holder.tv_state.setTextColor(context.getResources().getColor(R.color.bg_blue));
            holder.tv_state.setText("开启权限");
        }
        holder.tv_title.setText(quanXianBean.getTitle());
        holder.tv_des.setText(quanXianBean.getDes());
        return convertView;
    }
    class Holder{
        public TextView tv_state,tv_title,tv_des;
    }
}
